/*var width = 948;
var width_space = 4;
var width_max = 0;
var position = 0;
var number = 0;

var auto = true;
var time = 4000;
var timer;

function cpt(name){
	var i = 0;
	$(name+' li').each(function(){
		i++;
	});
	return i;
}
function init(name, auto_bool){
	number = cpt(name);	
	width_max = number * width + number * width_space;
	auto = auto_bool;
	launch_auto();
}

function anime(){
	position += width + width_space;
	if(position >= width_max){
		$('#slide-frb').animate({left : '0'});
		position = 0;
	}else{
		$('#slide-frb').animate({left : '-'+position+'px'});
	}
}

function launch_auto(){
	if(auto){
		timer = setInterval('anime()', time);
	}
}

function stop_auto(){
	clearInterval(timer);
}
 */
(function($) {
	//Taille de la div avec toutes les li
	var width_max = 0;
	//Position du left
	var position = 0;
	//Nombre de li
	var number = 0;
	//Interval id
	var timer;

	//Taille du slider
	var width;
	//Taille des espace
	var width_space;
	var auto;
	//Time de défilement
	var time;
	var frb_slide_selector;

	var anime = function() {
		position += width + width_space;
		if (position >= width_max) {
			$(frb_slide_selector).animate( {
				left : '0'
			});
			position = 0;
		} else {
			$(frb_slide_selector).animate( {
				left : '-' + position + 'px'
			});
		}
	}

	$.fn.frbSlideHeader = function(params) {
		frb_slide_selector = $(this);
		// Merge les paramètres par défaut et ceux de l'utilisateur
		params = $.extend( {
			width : '948',
			width_space : '0',
			auto : 'true',
			time : '4000'
		}, params);

		width = new Number(params.width);
		width_space = new Number(params.width_space);
		auto = new Number(params.auto);
		time = new Number(params.time);

		var i = 0;
		$(frb_slide_selector).children('li').each(function() {
			i++;
		});
		number = i;
		width_max = number * params.width + number * params.width_space;
		if (auto) {
			timer = setInterval(anime, time);
		}
		return this;
	};

	function stop_auto() {
		clearInterval(timer);
	}
})(jQuery);
